package com.yunfangdata.web.controller;


import com.yunfangdata.domain.Salary;
import com.yunfangdata.query.SalaryQueryObject;
import com.yunfangdata.service.ISalaryService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("salary")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @RequiresPermissions("salary:index")
    @PermissionName("工资首页")
    @RequestMapping("")
    public String index() {
        return "salary/list";
    }


    @RequiresPermissions("salary:list")
    @PermissionName("工资列表")
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(SalaryQueryObject qo) {
        return salaryService.query(qo);
    }


    @RequiresPermissions("salary:save")
    @PermissionName("工资表保存")
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Salary salary) {
        JsonResult js =new JsonResult();
        try {
            salaryService.save(salary);
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("工资表保存失败");
        }

        return js;
    }


    @RequiresPermissions("salary:delete")
    @PermissionName("工资表删除")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult js =new JsonResult();
        try {
            salaryService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("工资表保存失败");
        }

        return js;
    }



    @RequiresPermissions("salary:changeState")
    @PermissionName("工资表删除")
    @RequestMapping("changeState")
    @ResponseBody
    public JsonResult changeState(Long id) {
        JsonResult js =new JsonResult();
        try {
            salaryService.changeState(id);
        } catch (Exception e) {
            e.printStackTrace();
            js =new JsonResult("工资表审核失败");
        }

        return js;
    }










}
